<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 钉钉企业用户创建及修改请求类 v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace ding\request;

/**
 * 创建或者更新成员
 *
 * @package ding\request
 */
class UserSaveRequest extends DingApiRequest {
    /**
     * 工唯一标识ID（不可修改），企业内必须唯一。长度为1~64个字符，如果不传，服务器将自动生成一个userid
     * @var string
     */
    private $userid;
    /**
     * 成员名称。长度为1~64个字符
     * @var string
     */
    private $name;
    /**
     * 在对应的部门中的排序, Map结构的json字符串, key是部门的Id, value是人员在这个部门的排序值
     * @var array 示例：[1=>10, 3=>20]
     */
    private $orderInDepts;
    /**
     * 数组类型，数组里面值为整型，成员所属部门id列表
     * @var array
     */
    private $department;
    /**
     * 职位信息。长度为0~64个字符
     * @var string
     */
    private $position;
    /**
     * 手机号码，企业内必须唯一，不可重复
     * @var string
     */
    private $mobile;
    /**
     * 分机号，长度为0~50个字符，企业内必须唯一，不可重复
     * @var string
     */
    private $tel;
    /**
     * 办公地点，长度为0~50个字符
     * @var string
     */
    private $workPlace;
    /**
     * 备注，长度为0~1000个字符
     * @var string
     */
    private $remark;
    /**
     * 邮箱。长度为0~64个字符。企业内必须唯一，不可重复
     * @var string
     */
    private $email;
    /**
     * 员工的企业邮箱，员工的企业邮箱已开通，才能增加此字段， 否则会报错
     * @var string
     */
    private $orgEmail;
    /**
     * 员工工号。对应显示到OA后台和客户端个人资料的工号栏目。长度为0~64个字符
     * @var string
     */
    private $jobnumber;
    /**
     * 是否号码隐藏, true表示隐藏, false表示不隐藏。隐藏手机号后，手机号在个人资料页隐藏，但仍可对其发DING、发起钉钉免费商务电话。
     * @var bool
     */
    private $isHide;
    /**
     * 是否高管模式，true表示是，false表示不是。开启后，手机号码对所有员工隐藏。普通员工无法对其发DING、发起钉钉免费商务电话。高管之间不受影响。
     * @var bool
     */
    private $isSenior;
    /**
     * 扩展属性，可以设置多种属性(但手机上最多只能显示10个扩展属性，具体显示哪些属性，请到OA管理后台->设置->通讯录信息设置和OA管理后台->设置->手机端显示信息设置)
     * @var array 例如：["年龄":"20","性别":"男"]
     */
    private $extattr;

    /**
     * 构造函数隐藏
     */
    private function __construct() {
    }

    /**
     * 新增用户请求
     *
     * @param $name
     * @param $departmentIds
     * @param $mobile
     * @return static
     */
    public static function userCreateRequest($name, $departmentIds, $mobile) {
        $req = new static();
        $req->name = $name;
        $req->department = $departmentIds;
        $req->mobile = $mobile;
        return $req;
    }

    /**
     * 更新用户请求
     *
     * @param $userid
     * @return static
     */
    public static function userUpdateRequest($userid) {
        $req = new static();
        $req->userid = $userid;
        return $req;
    }

    /**
     * @return string
     */
    public function getUserid() {
        return $this->userid;
    }

    /**
     * @param string $userid
     * @return UserSaveRequest
     */
    public function setUserid($userid) {
        $this->userid = $userid;
        return $this;
    }

    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * @param string $name
     * @return UserSaveRequest
     */
    public function setName($name) {
        $this->name = $name;
        return $this;
    }

    /**
     * @return array
     */
    public function getOrderInDepts() {
        return $this->orderInDepts;
    }

    /**
     * @param array $orderInDepts
     * @return UserSaveRequest
     */
    public function setOrderInDepts($orderInDepts) {
        $this->orderInDepts = $orderInDepts;
        return $this;
    }

    /**
     * 设置成员在某个部门中的排序
     *
     * @param $deptId
     * @param $order
     * @return $this
     */
    public function setOrderInDept($deptId, $order) {
        if (!$this->orderInDepts) {
            $this->orderInDepts = [];
        }
        $this->orderInDepts[$deptId] = $order;
        return $this;
    }

    /**
     * @return array
     */
    public function getDepartment() {
        return $this->department;
    }

    /**
     * @param array $department
     * @return UserSaveRequest
     */
    public function setDepartment($department) {
        $this->department = $department;
        return $this;
    }

    /**
     * @return string
     */
    public function getPosition() {
        return $this->position;
    }

    /**
     * @param string $position
     * @return UserSaveRequest
     */
    public function setPosition($position) {
        $this->position = $position;
        return $this;
    }

    /**
     * @return string
     */
    public function getMobile() {
        return $this->mobile;
    }

    /**
     * @param string $mobile
     * @return UserSaveRequest
     */
    public function setMobile($mobile) {
        $this->mobile = $mobile;
        return $this;
    }

    /**
     * @return string
     */
    public function getTel() {
        return $this->tel;
    }

    /**
     * @param string $tel
     * @return UserSaveRequest
     */
    public function setTel($tel) {
        $this->tel = $tel;
        return $this;
    }

    /**
     * @return string
     */
    public function getWorkPlace() {
        return $this->workPlace;
    }

    /**
     * @param string $workPlace
     * @return UserSaveRequest
     */
    public function setWorkPlace($workPlace) {
        $this->workPlace = $workPlace;
        return $this;
    }

    /**
     * @return string
     */
    public function getRemark() {
        return $this->remark;
    }

    /**
     * @param string $remark
     * @return UserSaveRequest
     */
    public function setRemark($remark) {
        $this->remark = $remark;
        return $this;
    }

    /**
     * @return string
     */
    public function getEmail() {
        return $this->email;
    }

    /**
     * @param string $email
     * @return UserSaveRequest
     */
    public function setEmail($email) {
        $this->email = $email;
        return $this;
    }

    /**
     * @return string
     */
    public function getOrgEmail() {
        return $this->orgEmail;
    }

    /**
     * @param string $orgEmail
     * @return UserSaveRequest
     */
    public function setOrgEmail($orgEmail) {
        $this->orgEmail = $orgEmail;
        return $this;
    }

    /**
     * @return string
     */
    public function getJobnumber() {
        return $this->jobnumber;
    }

    /**
     * @param string $jobnumber
     * @return UserSaveRequest
     */
    public function setJobnumber($jobnumber) {
        $this->jobnumber = $jobnumber;
        return $this;
    }

    /**
     * @return bool
     */
    public function isHide() {
        return $this->isHide;
    }

    /**
     * @param bool $isHide
     * @return UserSaveRequest
     */
    public function setIsHide($isHide) {
        $this->isHide = $isHide;
        return $this;
    }

    /**
     * @return bool
     */
    public function isSenior() {
        return $this->isSenior;
    }

    /**
     * @param bool $isSenior
     * @return UserSaveRequest
     */
    public function setIsSenior($isSenior) {
        $this->isSenior = $isSenior;
        return $this;
    }

    /**
     * @return array
     */
    public function getExtattr() {
        return $this->extattr;
    }

    /**
     * @param array $extattr
     * @return UserSaveRequest
     */
    public function setExtattr($extattr) {
        $this->extattr = $extattr;
        return $this;
    }

    /**
     * @param $key
     * @param $value
     * @return $this
     */
    public function setExtattrItem($key, $value) {
        if (!$this->extattr) {
            $this->extattr = [];
        }
        $this->extattr[$key] = $value;
        return $this;
    }

    public function toData() {
        $data = parent::toData();
        if (!is_null($this->orderInDepts) && is_array($this->orderInDepts)) {
            $arr = [];
            foreach ($this->orderInDepts as $deptId => $order) {
                $arr[] = $deptId . ":" . $order;
            }
            $data['orderInDepts'] = "{" . join(',', $arr) . "}";
        }
        return $data;
    }

}